﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using MVCManage.Model;
using MVCManage.BLL;
using MVCManage.Api.Models;
using System.Xml.XPath;
using System.Security.Cryptography;
using Microsoft.Ajax.Utilities;
namespace MVCManage.Api.Controllers
{
    public class AuthController : ApiController
    {
        AuthorityBLL bll = new AuthorityBLL();

        // GET: api/Auth
        public ResultData<List<AuthDto>> GetAuthById(int rid) {
            var list = from n in bll.GetAuthByid(rid)
                       select new AuthDto()
                       {
                            AuthId=n.authID,
                             LastTime=DateTime.Now,
                              MenuID=n.menuID,
                               MenuName=n.Menus.menuName,
                               Sort=n.sort,
                                RoleID=n.roleID,
                       };
                  ResultData<List<AuthDto>> result = new ResultData<List<AuthDto>>();
            result.code = 1;
            result.msg = "ok";
            result.data = list.ToList();
            return result;


        }



        // POST: api/Auth
        public Result Post([FromBody] AddAuth auth)
        {
            bll.Deletes(auth.rid);
            var pd = bll.Add(auth.rid,auth.ids);
            Result result = new Result();
            result.code = pd ? 1 : 0;
            result.msg = pd ? "ok" : "ok";
            return result;

        }

        



    }
}
